package com.springboot2.infrastructure.service;

import com.alibaba.fastjson.JSONObject;
import com.springboot2.infrastructure.entity.TestObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

@Component
public class RedisService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate redisTemplate;

    public void setKey(String key, String value) {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        ops.set(key, value);
    }

    public String getValue(String key) {
        ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
        return ops.get(key);
    }


    @RequestMapping("/setObj")
    public void setObj(String key, Object obj) {
        redisTemplate.opsForValue().set(key,obj);
    }

    @RequestMapping("/getObj")
    public Object getObj(String key) {
        Object testObj = redisTemplate.opsForValue().get(key);
        return testObj;
    }

}
